package com.util.msn;
import java.io.IOException;
 
import rath.msnm.MSNMessenger;
import rath.msnm.SwitchboardSession;
import rath.msnm.UserStatus;
import rath.msnm.entity.MsnFriend;
import rath.msnm.event.MsnAdapter;
import rath.msnm.msg.MimeMessage;
 
/**
 * 测试java_msn
 * @author dtb
 *
 */
public class Test_Msn extends Thread { 
 private static MSNMessenger msn; 
 
 public static void main(String[] args) { 
  msn = new MSNMessenger( "zhu_you_long@hotmail.com", ""); //发送人 
  msn.setInitialStatus(UserStatus.ONLINE);
  
  //设置消息
  MimeMessage mime = new MimeMessage(); 
  mime.setKind(MimeMessage.KIND_MESSAGE);
  mime.setMessage("我正在www.367du.com上，你也来逛逛吧");
  
  msn.login();
 
  try {
   //设置延时
   Thread.currentThread().sleep(5000);
   
   //给陌生人发消息，先加对方为好友
   MsnFriend friend = new MsnFriend("yaoyao9446@126.com");//接收人
   msn.addFriend(friend.getLoginName());
   
   //设置session，取得于对方的会话
   SwitchboardSession switchboardSession = msn.doCallWait("yaoyao9446@126.com"); //接收人
   
   //设置延时
   Thread.currentThread().sleep(1000); 
   
   boolean success = false;
   
   //发送在线消息
   success = msn.sendMessage("yaoyao9446@126.com",mime);
   System.out.println("online message : " + success);
   if(!success) {
    //发送离线消息 TODO 
    mime.setKind(MimeMessage.KIND_MAIL_NOTIFY);
    success = msn.sendMessage("yaoyao9446@126.com",mime);
    System.out.println("outline message : " + success);
   }
  } catch (Exception e) { 
   e.printStackTrace(); 
  }
  //try {
   //避免好友上限，这里要删除好友
  // msn.removeFriend("zhu_you_long@hotmail.com");
 // } catch (IOException e) {
  // e.printStackTrace();
 // }
 } 
} 
